package c.i.a.a;

import android.content.Context;
import android.os.Handler;
import android.os.Handler.Callback;
import android.os.HandlerThread;
import java.net.HttpURLConnection;
import java.util.Locale;

public abstract class b {
    public Context a;
    public String b;
    public String c;
    public int d;
    public int e;
    public byte[] f;
    public int g = -1;
    public byte[] h = null;
    public int i = 1;
    public int j = 0;
    public boolean k = false;
    public HandlerThread l;
    public Handler m;
    public HttpURLConnection n = null;

    public class a implements Callback {
        /* JADX WARNING: Missing block: B:39:0x00a6, code skipped:
            if (r4 != null) goto L_0x00a8;
     */
        public boolean handleMessage(android.os.Message r10) {
            /*
            r9 = this;
            r10 = c.i.a.a.b.this;
            r0 = r10.j;
            r1 = r10.i;
            r2 = 0;
            if (r0 < r1) goto L_0x0013;
        L_0x0009:
            r10.k = r2;
            r10.j = r2;
            r10 = r10.l;
            r10.quit();
            return r2;
        L_0x0013:
            r0 = 0;
            r1 = 10000; // 0x2710 float:1.4013E-41 double:4.9407E-320;
            r3 = 1;
            r4 = new java.net.URL;	 Catch:{ all -> 0x00b6 }
            r5 = r10.c;	 Catch:{ all -> 0x00b6 }
            r4.<init>(r5);	 Catch:{ all -> 0x00b6 }
            r4 = r4.openConnection();	 Catch:{ all -> 0x00b6 }
            r4 = (java.net.HttpURLConnection) r4;	 Catch:{ all -> 0x00b6 }
            r10.n = r4;	 Catch:{ all -> 0x00b6 }
            r4.setConnectTimeout(r1);	 Catch:{ all -> 0x00b6 }
            r4 = r10.n;	 Catch:{ all -> 0x00b6 }
            r4.setReadTimeout(r1);	 Catch:{ all -> 0x00b6 }
            r4 = r10.d;	 Catch:{ all -> 0x00b6 }
            r5 = "GET";
            if (r4 == r3) goto L_0x004d;
        L_0x0034:
            r6 = 3;
            if (r4 == r6) goto L_0x004a;
        L_0x0037:
            r6 = 4;
            if (r4 == r6) goto L_0x0047;
        L_0x003a:
            r6 = 5;
            if (r4 == r6) goto L_0x0044;
        L_0x003d:
            r6 = 6;
            if (r4 == r6) goto L_0x0041;
        L_0x0040:
            goto L_0x004f;
        L_0x0041:
            r5 = "TRACE";
            goto L_0x004f;
        L_0x0044:
            r5 = "HEAD";
            goto L_0x004f;
        L_0x0047:
            r5 = "DELETE";
            goto L_0x004f;
        L_0x004a:
            r5 = "PUT";
            goto L_0x004f;
        L_0x004d:
            r5 = "POST";
        L_0x004f:
            r4 = r10.n;	 Catch:{ all -> 0x00b6 }
            r4.setRequestMethod(r5);	 Catch:{ all -> 0x00b6 }
            r4 = r10.e;	 Catch:{ all -> 0x00b6 }
            r10.c(r4);	 Catch:{ all -> 0x00b6 }
            r4 = r10.f;	 Catch:{ all -> 0x00b6 }
            if (r4 == 0) goto L_0x0076;
        L_0x005d:
            r4 = r4.length;	 Catch:{ all -> 0x00b6 }
            if (r4 <= 0) goto L_0x0076;
        L_0x0060:
            r4 = r10.n;	 Catch:{ all -> 0x00b6 }
            r4.setDoOutput(r3);	 Catch:{ all -> 0x00b6 }
            r4 = r10.n;	 Catch:{ all -> 0x00b6 }
            r4 = r4.getOutputStream();	 Catch:{ all -> 0x00b6 }
            r5 = r10.f;	 Catch:{ all -> 0x00b6 }
            r4.write(r5);	 Catch:{ all -> 0x00b6 }
            r4.flush();	 Catch:{ all -> 0x00b6 }
            r4.close();	 Catch:{ all -> 0x00b6 }
        L_0x0076:
            r4 = r10.n;	 Catch:{ all -> 0x00b6 }
            r4.connect();	 Catch:{ all -> 0x00b6 }
            r4 = r10.n;	 Catch:{ all -> 0x00a5 }
            r4 = r4.getResponseCode();	 Catch:{ all -> 0x00a5 }
            r10.g = r4;	 Catch:{ all -> 0x00a5 }
            r4 = r10.n;	 Catch:{ all -> 0x00a5 }
            r4 = r4.getInputStream();	 Catch:{ all -> 0x00a5 }
            r5 = new java.io.ByteArrayOutputStream;	 Catch:{ all -> 0x00a3 }
            r5.<init>();	 Catch:{ all -> 0x00a3 }
            r6 = 1024; // 0x400 float:1.435E-42 double:5.06E-321;
            r7 = new byte[r6];	 Catch:{ all -> 0x00a3 }
        L_0x0092:
            r8 = r4.read(r7, r2, r6);	 Catch:{ all -> 0x00a3 }
            if (r8 <= 0) goto L_0x009c;
        L_0x0098:
            r5.write(r7, r2, r8);	 Catch:{ all -> 0x00a3 }
            goto L_0x0092;
        L_0x009c:
            r5 = r5.toByteArray();	 Catch:{ all -> 0x00a3 }
            r10.h = r5;	 Catch:{ all -> 0x00a3 }
            goto L_0x00a8;
            goto L_0x00a6;
        L_0x00a5:
            r4 = r0;
        L_0x00a6:
            if (r4 == 0) goto L_0x00ab;
        L_0x00a8:
            r4.close();	 Catch:{ all -> 0x00b6 }
        L_0x00ab:
            r4 = r10.n;
            if (r4 == 0) goto L_0x00b4;
        L_0x00af:
            r4.disconnect();
            r10.n = r0;
        L_0x00b4:
            r0 = 1;
            goto L_0x00c4;
        L_0x00b6:
            r4 = move-exception;
            r4.printStackTrace();	 Catch:{ all -> 0x00e9 }
            r4 = r10.n;
            if (r4 == 0) goto L_0x00c3;
        L_0x00be:
            r4.disconnect();
            r10.n = r0;
        L_0x00c3:
            r0 = 0;
        L_0x00c4:
            if (r0 == 0) goto L_0x00cd;
        L_0x00c6:
            r4 = r10.g;
            r5 = r10.h;
            r10.b(r4, r5);
        L_0x00cd:
            r10 = c.i.a.a.b.this;
            if (r0 == 0) goto L_0x00db;
        L_0x00d1:
            r10.k = r2;
            r10.j = r2;
            r10 = r10.l;
            r10.quit();
            return r3;
        L_0x00db:
            r10 = r10.m;
            r0 = (long) r1;
            r10.sendEmptyMessageDelayed(r3, r0);
            r10 = c.i.a.a.b.this;
            r0 = r10.j;
            r0 = r0 + r3;
            r10.j = r0;
            return r2;
        L_0x00e9:
            r1 = move-exception;
            r2 = r10.n;
            if (r2 == 0) goto L_0x00f5;
        L_0x00ee:
            r2 = r10.n;
            r2.disconnect();
            r10.n = r0;
        L_0x00f5:
            throw r1;
            */
            throw new UnsupportedOperationException("Method not decompiled: c.i.a.a.b$a.handleMessage(android.os.Message):boolean");
        }
    }

    public b(Context context, String str) {
        String str2 = "";
        this.c = str2;
        if (str == null || str.length() <= 0) {
            str = str2;
        }
        this.a = context;
        this.b = str;
    }

    public synchronized void a(int i, int i2, byte[] bArr) {
        if (!this.k) {
            this.i = 2;
            this.d = i;
            this.e = i2;
            this.f = bArr;
            this.k = true;
            this.j = 0;
            HandlerThread handlerThread = new HandlerThread("request");
            this.l = handlerThread;
            handlerThread.start();
            Handler handler = new Handler(this.l.getLooper(), new a());
            this.m = handler;
            handler.sendEmptyMessage(1);
        }
    }

    public abstract boolean b(int i, byte[] bArr);

    public final void c(int i) {
        String str = i != 1 ? i != 2 ? "" : "application/octet-stream" : "application/json; charset=utf-8";
        if (str.length() > 0) {
            this.n.addRequestProperty("Content-Type", str);
        }
        HttpURLConnection httpURLConnection = this.n;
        StringBuilder g = c.b.a.a.a.g("sessionid=");
        g.append(this.b);
        httpURLConnection.addRequestProperty("Cookie", g.toString());
        try {
            HttpURLConnection httpURLConnection2;
            StringBuilder stringBuilder;
            str = Locale.getDefault().getLanguage();
            String str2 = ",";
            String str3 = "Accept-Language";
            if (str.equalsIgnoreCase("zh")) {
                httpURLConnection2 = this.n;
                stringBuilder = new StringBuilder();
                stringBuilder.append(Locale.getDefault().toString());
                stringBuilder.append(str2);
                stringBuilder.append(str);
                str = ";q=0.9";
            } else {
                httpURLConnection2 = this.n;
                stringBuilder = new StringBuilder();
                stringBuilder.append(Locale.getDefault().toString());
                stringBuilder.append(str2);
                stringBuilder.append(str);
                str = ";q=0.9,en-US;q=0.6,en;q=0.4";
            }
            stringBuilder.append(str);
            httpURLConnection2.addRequestProperty(str3, stringBuilder.toString());
        } catch (Throwable unused) {
        }
    }
}
